#coding=utf-8
'''
Created on 2013年9月3日

@author: xuben

后端推送处理
'''

import Logger

#武将推送
PUSH_GENERAL = 'push@general'
#世界推送
PUSH_WORLD = 'push@cities'
#角色推送
PUSH_PLAYER = 'push@player'
#资源区推送
PUSH_RESOURCE = 'push@building'
#各种消息推送
PUSH_NOTICE = 'push@notice'
PUSH_RIGHT_NOTICE = 'push@rightNotice'
PUSH_CITY_MESSAGE = 'push@citymessage'

callback_map = {}

def init():
    callback_map[PUSH_GENERAL] = None
    callback_map[PUSH_WORLD] = None
    callback_map[PUSH_PLAYER] = None
    callback_map[PUSH_RESOURCE] = None
    callback_map[PUSH_NOTICE] = None
    callback_map[PUSH_RIGHT_NOTICE] = None
    callback_map[PUSH_CITY_MESSAGE] = None

def setCallback(command, callback):
    callback_map[command] = callback

def callback(command, data):
    if command in callback_map:
        func = callback_map[command]
        if func != None:
            func(data)
    else:
        Logger.log("未处理的后端推送\n" + command + "\n" + str(data), Logger.LOGGER_SOCKET)
        